<!DOCTYPE html>
<html xmlns:layout="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
	layout:decorate="~{common/layoutAdmin}">

<head>
	<meta charset="UTF-8">
	<title>帖子评论</title>
</head>

<body>
	<div layout:fragment="fragment_body">
		<el-row :gutter="20">
			<el-col :span="24">
				<!--<el-button type="primary" @click="openRaceComment(null)">添 加</el-button>-->
				<el-table :data="raceComments" border highlight-current-row style="width: 100%">
					<!-- -->
					<!--<el-table-column prop="commentParentId" label="所在评论">
						<template slot-scope="scope">
						{{scope.row.infoPublish?.accountName}}
						</template>
					</el-table-column>-->
					<el-table-column prop="commentPostId" label="所在帖子">
						<template slot-scope="scope">
						{{scope.row.post?.postText}}
						</template>
					</el-table-column>
					<el-table-column prop="commentUserId" label="评论人">
						<template slot-scope="scope">
						{{scope.row.user?.accountName}}
						</template>
					</el-table-column>
					<el-table-column prop="commentText" label="内容"></el-table-column>
					<el-table-column prop="commentTime" label="时间"></el-table-column>
					<el-table-column label="操作" width="160px">
						<template slot-scope="scope">
							<!--<el-button @click="openRaceComment(scope.row)" type="text" size="small">修 改</el-button>-->
							<el-popconfirm title="是否删除？" @confirm="delRaceComment(scope.row.commentId)">
								<el-button slot="reference" type="text" size="small">删 除</el-button>
							</el-popconfirm>
						</template>
					</el-table-column>
				</el-table>
			</el-col>
		</el-row>
		<!--弹框-->
		<el-dialog :title="raceCommentForm.ttitle" :visible.sync="raceCommentForm.visible" width="30%">
			<el-form :model="raceCommentForm" :rules="raceCommentRules" ref="raceCommentForm" label-width="100px">
				<!-- -->
				<el-form-item label="所在评论" prop="commentParentId">
					<el-input v-model="raceCommentForm.commentParentId"></el-input>
				</el-form-item>
				<el-form-item label="所在帖子" prop="commentPostId">
					<el-input v-model="raceCommentForm.commentPostId"></el-input>
				</el-form-item>
				<el-form-item label="评论人" prop="commentUserId">
					<el-input v-model="raceCommentForm.commentUserId"></el-input>
				</el-form-item>
				<el-form-item label="内容" prop="commentText">
					<el-input v-model="raceCommentForm.commentText"></el-input>
				</el-form-item>
				<el-form-item label="时间" prop="commentTime">
					<el-input v-model="raceCommentForm.commentTime"></el-input>
				</el-form-item>
			</el-form>
			<span slot="footer" class="dialog-footer">
				<el-button @click="closeRaceComment">取 消</el-button>
				<el-button type="primary" @click="saveRaceComment">保 存</el-button>
			</span>
		</el-dialog>
	</div>
</body>
<script type="text/javascript" layout:fragment="fragment_script">
	let vueData = {
		raceComments: [],
		selectRaceComment: null,
		raceCommentForm: {
			visible: false,
			ttitle: '新增/修改',
			commentId : '',
			commentParentId : '',
			commentPostId : '',
			commentUserId : '',
			commentText : '',
			commentTime : '',
		},
		raceCommentQuery: {
			userId: 'not',
			postId: '',
			page: '',
			size: '',
		},
		raceCommentRules: {
			commentId: [
				{required: true, message: '不能为空', trigger: 'blur'}
			],
			commentParentId: [
				{required: true, message: '不能为空', trigger: 'blur'}
			],
			commentPostId: [
				{required: true, message: '不能为空', trigger: 'blur'}
			],
			commentUserId: [
				{required: true, message: '不能为空', trigger: 'blur'}
			],
			commentText: [
				{required: true, message: '不能为空', trigger: 'blur'}
			],
			commentTime: [
				{required: true, message: '不能为空', trigger: 'blur'}
			],
		},
	}
	let vueMethods = {
		getRaceComments() {
			let that = this
			postRequst('/getComments', that.raceCommentQuery, true).then(function (resp) {
				that.raceComments = resp.rows
				if (resp.rows && resp.rows.length > 0) {
					that.selectRaceComment = resp.rows[0]
				}
			})
		},
		openRaceComment(row) {
			let that = this
			if (row) {
				that.raceCommentForm.ttitle = '修改'
				that.raceCommentForm.commentId = row.commentId
				that.raceCommentForm.commentParentId = row.commentParentId
				that.raceCommentForm.commentPostId = row.commentPostId
				that.raceCommentForm.commentUserId = row.commentUserId
				that.raceCommentForm.commentText = row.commentText
				that.raceCommentForm.commentTime = row.commentTime
			} else {
				that.raceCommentForm.ttitle = '新增'
				that.raceCommentForm.commentId = ''
				that.raceCommentForm.commentParentId = ''
				that.raceCommentForm.commentPostId = ''
				that.raceCommentForm.commentUserId = ''
				that.raceCommentForm.commentText = ''
				that.raceCommentForm.commentTime = ''
			}
			that.raceCommentForm.visible = true
		},
		closeRaceComment() {
			this.$refs["raceCommentForm"].resetFields();
			this.raceCommentForm.visible = false
		},
		saveRaceComment() {
			let that = this
			this.$refs["raceCommentForm"].validate((valid) => {
				if (valid) {
					postRequst('/admin/saveRaceComment', that.raceCommentForm).then(function (resp) {
						if (resp.status == 0) {
							that.getRaceComments()
							that.raceCommentForm.visible = false
							that.$message({message: resp.msg, type: "success"});
						} else {
							that.$message({message: resp.msg, type: "error"});
						}
					})
				}
			});
		},
		delRaceComment(commentId) {
			let that = this
			postRequst('/delComment', {commentId: commentId}, true).then(function (resp) {
				if (resp.status == 0) {
					that.getRaceComments()
					that.$message({message: resp.msg, type: "success"});
				} else {
					that.$message({message: resp.msg, type: "error"});
				}
			})
		},
	}
	function vueCreated() {
		let that = this
		that.getRaceComments()
	}
</script>

</html>